/*
 * @Author: yxw
 * @Date: 2019-3-15 15:41:17
 * @Last Modified by: yxw
 * @Last Modified time: 2019-02-25 15:50:39
 * @Description: 系统管理相关api
 */

import request from '@/router/axios'
import {systemUrls} from '@/const/apiUrl'

/**
 * 获取部门树
 * @param {*} query
 */
export function getDeptTree (query) {
  return request({
    url: systemUrls.deptTree,
    method: 'get',
    params: query
  })
}

/**
 * 返回该部门的单位
 * @param {*} query
 */
export function getTwoUnit (query) {
  return request({
    url: systemUrls.getTwoUnit,
    method: 'get',
    params: query
  })
}

/**
 * 获取协同部门树
 * @param {*} query
 */
export function getDeptXieTree (query) {
  return request({
    url: systemUrls.deptXieTree,
    method: 'get',
    params: query
  })
}

/**
 * 根据Id查询部门
 */
export function getDept (deptId) {
  return request({
    url: systemUrls.deptUrl + deptId,
    method: 'get'
  })
}


/**
 * 通过部门ID查询用户信息s
 */
export function getUsersByUnitId (deptId) {
  return request({
    url: systemUrls.getUsersByUnitId + deptId,
    method: 'get'
  })
}

/**
 * 获取当前用户全部信息
 */
export function getCurrentUserDetail () {
  return request({
    url: systemUrls.getCurrentUserDetail,
    method: 'get'
  })
}

/**
 * 附件下载
 */
export function downloadFile (fileId) {
  return request({
    url: systemUrls.downloadUrl + fileId,
    method: 'get',
    headers:{
      'Content-Type': 'application/json; application/octet-stream'
    },
    responseType: 'blob',
  })
}

/**
 * 上传文件
 */
export function UploadFile (obj, type, uploader) {
  if(uploader){
    return request({
      url: systemUrls.UploadFile,
      method: 'post',
      data: obj,
      params:type,
      timeout: 5*1000*60,
      onUploadProgress: progressEvent => {
        let percent=(progressEvent.loaded / progressEvent.total * 100) | 0;
        //调用onProgress方法来显示进度条，需要传递个对象 percent为进度值
        uploader.onProgress({percent:percent})
      }
    })
  }else{
    return request({
      url: systemUrls.UploadFile,
      method: 'post',
      data: obj,
      params:type,
      timeout: 5*1000*60
    })
  }
}

/**
 * 下载文件
 */
export function filedownload (fileId) {
  return request({
    url: systemUrls.downloadUrl+fileId,
    method: 'get',
    responseType: 'blob'
  })
}

/**
 * 得到文件信息
 */
export function getfileinfo (fileId) {
  return request({
    url: systemUrls.getfileinfo+fileId,
    method: 'get',
  })
}

/**
 * 根据id数组得到多个文件信息
 */
export function getfileinfopage (obj) {
  return request({
    url: systemUrls.getfileinfopage,
    method: 'get',
    params:obj
  })
}

/**
 * 得到地区
 */
export function getAreaByType (obj) {
  return request({
    url: systemUrls.getAreaByType,
    method: 'get',
    params: obj
  })
}

/**
 * 得到未读消息
 */
export function getunreadMsg (query) {
  return request({
    url: systemUrls.getunreadMsg,
    method: 'get',
    params:query
  })
}

/**
 * 得到未读消息详情
 */
export function getunreadcontent (messageId) {
  return request({
    url: systemUrls.getunreadcontent+messageId,
    method: 'get',
  })
}

/**
 * 将未读消息标为已读
 */
export function toHaveRead (obj) {
  return request({
    url: systemUrls.toHaveRead,
    method: 'put',
    params: obj
  })
}
/**
 * 创建备用文件记录-拟文需要
 * @param {*} query
 */
export function webOfficeCreateSpare () {
  return request({
    url: systemUrls.webOfficeCreateSpare,
    method: 'post',
  })
}
// signature  签章
export function toCreateSignature (id) {
  return request({
    url: '/file/'+id,
    method: 'get',
  })
}
